//
//  XxViewController.m
//  维度科技
//
//  Created by 谷银行 on 2019/1/23.
//  Copyright © 2019 谷银行. All rights reserved.
//

#import "XxViewController.h"
#import "NewsViewController.h"
#import "LinkmanViewController.h"
@interface XxViewController (){
    NewsViewController *news;
    LinkmanViewController *link;
}
@property (nonatomic,strong)UITableView *table;
@property (nonatomic,strong)NSMutableArray *arr;
@end

@implementation XxViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNav];
    
    [self.view addSubview:self.table];
}
- (void)CreateNav{
    
    self.navigationController.navigationBar.barTintColor=[UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0];
    //设置导航条右按钮
    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];
    self.navigationItem.rightBarButtonItem=right;
    //设置右按钮颜色
    [right setTintColor:[UIColor darkGrayColor]];
    //设置导航条分页控制器按钮
    UISegmentedControl *seg=[[UISegmentedControl alloc]initWithItems:@[@"消息",@"联系人"]];
    seg.frame=CGRectMake(111, 0, 188, 35);
    seg.layer.cornerRadius=16;
    seg.layer.masksToBounds=YES;
    
    //设置点击的颜色
    seg.tintColor = [UIColor colorWithRed:72/255.0 green:142/255.0 blue:247/255.0 alpha:1.0];
    //文字颜色
    UIColor *segmentColor = [UIColor darkGrayColor];
    
    NSDictionary *colorAttr = [NSDictionary dictionaryWithObjectsAndKeys:segmentColor, NSForegroundColorAttributeName,[UIFont systemFontOfSize:18],NSFontAttributeName,nil];
    [seg setTitleTextAttributes:colorAttr forState:UIControlStateNormal];
    
    //默认选中第一个界面
    seg.selectedSegmentIndex = 0;
    //设置边框颜色
    seg.layer.borderColor = [UIColor colorWithRed:72/255.0 green:142/255.0 blue:247/255.0 alpha:1.0].CGColor;
    //设置边框宽度 ****注：如果不设置宽度就是出现边框模糊状态
    seg.layer.borderWidth = 1;
    
    [seg addTarget:self action:@selector(segmtAction:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.titleView=seg;
    //消息页面
    news=[[NewsViewController alloc]init];
    //联系人页面
    link=[[LinkmanViewController alloc]init];
    //将子控制器添加到视图上
    [self addChildViewController:news];
    
    [self addChildViewController:link];
    
    [self.view addSubview:news.view];
    
    //[self.view addSubview:link.view];
    
}


- (void)segmtAction:(UISegmentedControl *)seg{
    
    int index = (int)seg.selectedSegmentIndex;
    switch (index) {
            //根据下标选择控制器
        case 0:
            [self.view addSubview:news.view];
            [link.view removeFromSuperview];
            break;
        case 1:
            [self.view addSubview:link.view];
            [news.view removeFromSuperview];
            break;
        default:
            break;
    }
    
}

@end
